package websocket;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {
	private static Logger log = Logger.getLogger(SystemWebSocketHandler.class);
	
	@Resource
	private WebSocketHandler webSocketHandler;
	@Resource
	private HandshakeInterceptor handshakeInterceptor;
	
	public WebSocketConfig() {
	}

	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		registry.addHandler(webSocketHandler, "/websck.do").addInterceptors(handshakeInterceptor);
		log.info("registed!");
		registry.addHandler(webSocketHandler, "/sockjs/websck.do").addInterceptors(handshakeInterceptor)
        .withSockJS();

	}
}
